<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\MemberService\MemberBankService;
use Hyperf\Di\Annotation\Inject;

/**
 * 用户银行卡管理
 * @author huj
 * @Controller(prefix="/webapi/v1/memberbank")
 * @Middleware(WebApiMiddleware::class)
 */
class MemberBankController extends AbstractController
{
     /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var MemberBankService
     */
    protected $memberBankService;

    /**
     * 绑定的银行卡列表
     * @RequestMapping(path="bankList", methods="get,post")
     */
    public function bankList(RequestInterface $request)
    {
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBankService->bankList($param);
    }
    
    /**
     * 新增银行卡
     * @RequestMapping(path="addBank", methods="get,post")
     */
    public function addBank(RequestInterface $request)
    {
        $param        = $request->inputs(['true_name', 'bankcard','mobile','card_type','idcard','bank_id','code','org_code','org_name']);
        $param['mid'] = $request->getAttribute('mid');
        $param['cid'] = $request->getAttribute('cid');
        return $this->memberBankService->addBank($param);
    }
    
    /**
     * 新增银行卡
     * @RequestMapping(path="editBank", methods="get,post")
     */
    public function editBank(RequestInterface $request)
    {
        $param        = $request->inputs(['id','true_name', 'bankcard','mobile','card_type','idcard','bank_id','code','org_code','org_name']);
        $param['mid'] = $request->getAttribute('mid');
        $param['cid'] = $request->getAttribute('cid');
        return $this->memberBankService->editBank($param);
    }

    /**
     * 银行卡详情
     * @RequestMapping(path="detail", methods="get,post")
     */
    public function detail(RequestInterface $request)
    {
        $param        = $request->inputs(['id']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBankService->detail($param);
    }

    /**
     * 删除银行卡
     * @RequestMapping(path="delBank", methods="get,post")
     */
    public function delBank(RequestInterface $request)
    {
        $param        = $request->inputs(['id']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBankService->delBank($param);
    }
}